<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>刮刮乐效果</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        canvas {
            background-image: url("https://api.ixiaowai.cn/mcapi/mcapi.php");
        }
    </style>
</head>

<body>
    <canvas></canvas>
    <script>
        const can = document.querySelector("canvas"),
            ctx = can.getContext("2d");

        can.width = window.innerWidth;
        can.height = window.innerHeight;

        const img = document.createElement("img");
        img.src = "https://api.ixiaowai.cn/api/api.php";

        img.onload = (_) => {
            ctx.drawImage(img, 0, 0);
        };

        can.onmousedown = (_) => {
            can.onmousemove = (e) => {
                ctx.beginPath();
                ctx.fillStyle = "#eee";
                ctx.arc(e.offsetX, e.offsetY, 30, 0, Math.PI * 2);
                ctx.fill();
                ctx.globalCompositeOperation = "destination-out";
            };
        };

        can.onmouseup = _ => can.onmousemove = null
    </script>
</body>

</html>